package com.mingmen.supplier.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.mingmen.supplier.R;
import com.mingmen.supplier.defineview.GlideRoundTransform;
import com.mingmen.supplier.httpconfig.AppConfig;
import com.mingmen.supplier.model.NewOrderDetailModel;

import java.util.ArrayList;
import java.util.List;


public class NewDaiPeiSongAdapter extends RecyclerView.Adapter<NewDaiPeiSongAdapter.ViewHolder> {
    List<NewOrderDetailModel.DataBean.BillDetailsBean> myLiveList = new ArrayList<>();
    Context mContext;
    private OnItemClickListener mOnItemClickListener;
    private int checkedPosition = -1;

    //recycleview标签
    public void setCheckedPosition(int checkedPosition) {
        this.checkedPosition = checkedPosition;
        notifyDataSetChanged();
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClickListener(View view, int pos, List<NewOrderDetailModel.DataBean.BillDetailsBean> myLiveList);
    }


    public NewDaiPeiSongAdapter(Context context, List<NewOrderDetailModel.DataBean.BillDetailsBean> myLiveList) {
        this.mContext = context;
        this.myLiveList = myLiveList;

    }

    public void setDataList(List<NewOrderDetailModel.DataBean.BillDetailsBean> list) {
        myLiveList = list;

        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_new_daipeisong, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }


    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        NewOrderDetailModel.DataBean.BillDetailsBean dataBean = myLiveList.get(position);


        Glide.with(mContext).load(AppConfig.IMGURL + dataBean.getPicture()).dontAnimate().placeholder(R.mipmap.default_pic).error(R.mipmap.default_pic).transform(new GlideRoundTransform(mContext, 5)).into(holder.img_logo);
        holder.commodityName.setText(dataBean.getCommodityName());
        holder.spec.setText("规格:" + dataBean.getSpec());
        holder.describe.setText(dataBean.getDescribe());
        holder.shijia.setText(dataBean.getShijia());
        holder.arrivePrice.setText(dataBean.getConfirmPrice());
        holder.applyAmount.setText(dataBean.getApplyAmount() + "");
        holder.arriveAmount.setText(dataBean.getArriveAmount());

        holder.shijia.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickListener.onItemClickListener(v, position, myLiveList);
            }
        });
        holder.arriveAmount.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickListener.onItemClickListener(v, position, myLiveList);
            }
        });

    }

    @Override
    public int getItemCount() {
        return myLiveList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        ImageView img_logo;
        TextView commodityName;
        TextView spec;
        TextView describe;


        TextView applyAmount;

        TextView arrivePrice;
        TextView arriveAmount;
        TextView shijia;

        public ViewHolder(View itemView) {
            super(itemView);

            img_logo = (ImageView) itemView.findViewById(R.id.img_logo);
            commodityName = (TextView) itemView.findViewById(R.id.commodityName);
            spec = (TextView) itemView.findViewById(R.id.spec);
            describe = (TextView) itemView.findViewById(R.id.describe);

            applyAmount = (TextView) itemView.findViewById(R.id.applyAmount);
            arriveAmount = (TextView) itemView.findViewById(R.id.arriveAmount);
            arrivePrice = (TextView) itemView.findViewById(R.id.arrivePrice);
            shijia = (TextView) itemView.findViewById(R.id.shijia);
        }
    }


}
